-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(entgql): check fields RType for Map and use Map scalar if possible #455
Conversation
Thanks for the contribution, @tankbusta 🙏🏻 Can you add a simple test for this? A field in one of these schemas: /~https://github.com/ent/contrib/tree/master/entgql/internal/todo/ent/schema |
cce019e
to
21984a2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
@@ -773,6 +773,13 @@ func (e *schemaGenerator) mapScalar(gqlType string, f *gen.Field, ant *Annotatio | |||
case "[]string": | |||
scalar = "[String!]" | |||
} | |||
case reflect.Map: | |||
if f.Type.RType.Ident == "map[string]interface {}" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the spacing between interface
and {}
really weird. But the test passed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I was confused when I saw that at first but I think it's just how the reflect
package identifies interface{}
. You can see the same format in some of their tests: /~https://github.com/golang/go/blob/master/src/reflect/all_test.go#L713
Signed-off-by: Giau. Tran Minh <hello@giautm.dev>
b52fa06
to
5323245
Compare
Thank @tankbusta for your contribution. Good to see your here again, <3 |
If you create an entity with a JSON field...
You will get an error when running code generation
You can resolve this today by adding the annotation
entgql.Type("Map")
but I didn't see any mention that this was required so I made the code a little bit smarter by checking if it's ofmap[string]interface {}
and using the built-inMap
scalar. If you do not set this, the error is made smarter by recommending that you setentgql.Type
.